﻿namespace _01.StudentExercise
{
    using System;

    public class Student : ICloneable, IComparable<Student>
    {
        public Student(string firstName, string middleName, string lastName, string ssn, string address, string mobilePhone, byte course, string email, Specialties specialties, Universities universities, Faculties faculties)
        {
            this.FirstName = firstName;
            this.MiddleName = middleName;
            this.LastName = lastName;
            this.Ssn = ssn;
            this.Address = address;
            this.MobilePhone = mobilePhone;
            this.Course = course;
            this.Email = email;
            this.Specialties = specialties;
            this.Universities = universities;
            this.Faculties = faculties;
        }

        public string FirstName { get; set; }

        public string MiddleName { get; set; }

        public string LastName { get; set; }

        public string Ssn { get; set; }

        public string Address { get; set; }

        public string MobilePhone { get; set; }

        public byte Course { get; set; }

        public string Email { get; set; }

        public Specialties Specialties { get; set; }

        public Universities Universities { get; set; }

        public Faculties Faculties { get; set; }

        public static bool operator ==(Student firstStudent, Student secondStudent)
        {
            return Student.Equals(firstStudent, secondStudent);
        }

        public static bool operator !=(Student firstStudent, Student secondStudent)
        {
            return !Student.Equals(firstStudent, secondStudent);
        }

        public int CompareTo(Student otherStudent)
        {
            if (this.FirstName != otherStudent.FirstName)
            {
                return this.FirstName.CompareTo(otherStudent.FirstName);
            }

            if (this.MiddleName != otherStudent.MiddleName)
            {
                return this.MiddleName.CompareTo(otherStudent.MiddleName);
            }

            if (this.LastName != otherStudent.LastName)
            {
                return this.LastName.CompareTo(otherStudent.LastName);
            }

            if (this.Ssn != otherStudent.Ssn)
            {
                return this.Ssn.CompareTo(otherStudent.Ssn);
            }

            return 0;
        }

        object ICloneable.Clone()
        {
            return this.Clone();
        }

        public Student Clone()
        {
            Student newStudent = new Student(this.FirstName, this.MiddleName, this.LastName, this.Ssn,
                this.Address, this.MobilePhone, this.Course, this.Email, this.Specialties, this.Universities, this.Faculties);
            return newStudent;
        }

        public override string ToString()
        {
            return string.Format("Name: {0} {1} {2}, Ssn: {3}, Universities: {4}, Specialties: {5}, Course: {6}, MobilePhone: {7}, E-mail: {8}",
                this.FirstName, this.MiddleName, this.LastName, this.Ssn, this.Universities, this.Specialties, this.Course, this.MobilePhone, this.Email);
        }

        public override int GetHashCode()
        {
            unchecked
            {
                int result = 17;
                result = (result * 23) + ((this.FirstName != null) ? this.FirstName.GetHashCode() : 0);
                result = (result * 23) + ((this.MiddleName != null) ? this.MiddleName.GetHashCode() : 0);
                result = (result * 23) + ((this.LastName != null) ? this.LastName.GetHashCode() : 0);
                result = (result * 23) + ((this.Ssn != null) ? this.Ssn.GetHashCode() : 0);
                return result;
            }
        }

        public bool Equals(Student value)
        {
            if (ReferenceEquals(null, value))
            {
                return false;
            }

            if (ReferenceEquals(this, value))
            {
                return true;
            }

            return object.Equals(this.FirstName, value.FirstName) &&
                   object.Equals(this.MiddleName, value.MiddleName) &&
                   object.Equals(this.LastName, value.LastName) &&
                   object.Equals(this.Ssn, value.Ssn);
        }

        public override bool Equals(object obj)
        {
            Student temp = obj as Student;
            if (temp == null)
            {
                return false;
            }

            return this.Equals(temp);
        }
    }
}